//
//  SharListTableCell.m
//  NormalFramework
//
//  Created by beisheng03 on 2018/3/13.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "SharListTableCell.h"
#import "ImageBrowser.h"

@interface SharListTableCell ()

@property (weak, nonatomic) IBOutlet ImageBrowser *myCollectionVeiw;
@property (weak, nonatomic) IBOutlet UIImageView *headerIcon;
@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *detalLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewH;
@property (nonatomic, strong) NSMutableArray<NSURL *> *urls;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;


@end

@implementation SharListTableCell

- (NSMutableArray<NSURL *> *)urls{
    if (!_urls) {
        _urls = [NSMutableArray array];
    }
    
    
    return _urls;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.bottomMargin.constant = 0;
    
    
    self.nickNameLabel.font = BigTitleFont;
  
    
    self.headerIcon.layer.cornerRadius = 26;
    self.headerIcon.layer.masksToBounds = YES;
    
    [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:DefualHeaderStr]];
    
    self.detalLabel.attributedText = [self attributedString:@"谢谢主持人。我们知道，今年5月8日是汶川地震十周年，在当年灾后重建过程中，其实还有一场所谓的信任力危机，就是中国红十字会被曝出用1300万元购买了1000顶的天价帐篷，由此引发了一场巨大的信任力危机，而且在不久之后，应该是2011年的时候，又有一起公共事件，就是郭美美炫富事件，这个事件更是把中国红十字会的公信力问题推到了风口浪尖上。我们注意到去年的时候，全国人大常委会对红十字法进行了修订，这部法律于去年5月8日正式实施了，我们的问题是，在应对社会公众热点事件引发的信任力危机方面，立法究竟会起到多么大的作用？这部法律对提高红十字会的履行能力有哪些具体的规定?" withFont:SubTitleFont];
    
    self.detalLabel.textColor = darkGray;
}


- (void)setURLStrings:(NSArray<NSString *> *)URLStrings{
    
    _URLStrings = URLStrings;
    
    [self.urls removeAllObjects];
    
    for (NSString *urlstr in URLStrings) {
        
        
        [self.urls addObject:[NSURL URLWithString:urlstr]];
    }
    
    
    self.myCollectionVeiw.thumPicURLs = self.urls;
    
    BrowserLayout *layout = (BrowserLayout *)self.myCollectionVeiw.collectionViewLayout;
    
    layout.itemSize = [layout itemSizeWitUrls:self.urls withMargin:KScreenW * 0.3];
    
    CGSize tempSize = [layout myCollectionViewSizeWitUrls:self.urls withMargin:KScreenW * 0.3];
    
    self.collectionViewW.constant = tempSize.width;
    
    self.collectionViewH.constant = tempSize.height;
    
    [self.myCollectionVeiw reloadData];
    
    
    
    
}




- (NSAttributedString *)attributedString:(NSString *)str withFont:(UIFont *)font{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSKernAttributeName value:@(1.0f) range:NSMakeRange(0, str.length)];
    
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
    
    para.lineSpacing = 1;
    
    //    para.firstLineHeadIndent = 20;
    
    [attr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, str.length)];
    
    
    return attr;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
